package reduce.fz.com.reduce.activity;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.alibaba.fastjson.TypeReference;

import de.greenrobot.event.EventBus;
import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.abstracts.AbResponseListener;
import reduce.fz.com.reduce.bean.ServiceException;
import reduce.fz.com.reduce.bean.Society;
import reduce.fz.com.reduce.bean.SocietyNotice;
import reduce.fz.com.reduce.bean.result.Result;
import reduce.fz.com.reduce.event.SocietyNoticeEvent;
import reduce.fz.com.reduce.service.SocietyService;
import reduce.fz.com.reduce.util.ServiceBuilder;

public class PubNoticeActivity extends BaseToolBarActivity {


    private EditText mEtComment;
    private TextView tvSave;
    private Long sid;

    private SocietyService societyService = ServiceBuilder.builderSocietyService(null);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pub_notice);
        setToolbarTitle("编辑内容");
        mEtComment = (EditText) findViewById(R.id.et_comment);
        sid = getIntent().getLongExtra("sid", 0l);
        tvSave = setRightBtn("保存");
        initWidget();
    }

    @Override
    public void initWidget() {
        tvSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Intent intent = new Intent();
                SocietyNotice notice = new SocietyNotice();
                notice.sid = sid;
                notice.description = mEtComment.getText().toString();
                notice.pubtime = System.currentTimeMillis();
                societyService.addSocietyNotice(notice, new AbResponseListener<SocietyNotice>(new TypeReference<Result<SocietyNotice>>() {
                }) {
                    @Override
                    public void error(ServiceException e) {
                    }

                    @Override
                    public void responseInfo(Result<SocietyNotice> data) {
                        if (data.getData() != null)
                            EventBus.getDefault().post(new SocietyNoticeEvent(data.getData(), SocietyNoticeEvent.CODE_ADD));
                        setResult(RESULT_OK, intent);
                        finish();
                    }
                });

            }
        });
    }

    @Override
    public void initListener() {

    }

}
